//////////////////////////////////////////////////
// glVertexBO.hpp
//
// Author: Tarik Belabbas et Adrien Hoffer
//////////////////////////////////////////////////

#include "glVertexBO.h"

//------------------------------------------------------------------------------
glVertexBO::glVertexBO()
{
	m_bufferName	= -1;
}

//------------------------------------------------------------------------------
glVertexBO::~glVertexBO()
{
	glDeleteBuffers( 1, ( const GLuint* )&m_bufferName );
}

//------------------------------------------------------------------------------
void glVertexBO::genBuffer()
{
	if ( m_bufferName != -1 )
		glDeleteBuffers( 1, ( const GLuint* )&m_bufferName );

	glGenBuffers( 1, ( GLuint* )&m_bufferName );
}

//------------------------------------------------------------------------------
void glVertexBO::bindBuffer( GLenum _target )
{
	glBindBuffer( _target, ( GLuint )m_bufferName );
}

//------------------------------------------------------------------------------
void glVertexBO::unbindBuffer( GLenum _target )
{
	glBindBuffer( _target, NULL );
}

//------------------------------------------------------------------------------
void glVertexBO::storeData( GLenum _target, GLenum _usage, const void* _pointer,
		unsigned int _size )
{
	if ( m_bufferName != -1 )
	{
		glBindBuffer( _target, ( GLuint )m_bufferName );
		//glBufferData( _target, sizeof( Type ) * m_buffer.size(),
		//		( const GLvoid* )&( m_buffer[ 0 ] ), _usage );
		glBufferData( _target, _size, _pointer, _usage );
	}
}

//------------------------------------------------------------------------------
void* glVertexBO::mapBuffer( GLenum _target, GLenum _access )
{
	return glMapBuffer( _target, _access );
}

//------------------------------------------------------------------------------
GLboolean glVertexBO::unmapBuffer( GLenum _target )
{
	return glUnmapBuffer( _target );
}
